using System;

namespace atm
{
    public class Account(string name, string accountNumber)
    {
        public string Name { get; } = name;
        public string AccountNumber { get; } = accountNumber;
        public decimal Balance { get; protected set; } = 0; 
        
        public void Deposit(decimal amount)
        {
            Balance += amount;
        }
        
        public virtual void Withdraw(decimal amount)
        {
            if (amount > Balance)
            {
                throw new InvalidOperationException("余额不足");
            }

            Balance -= amount;
        }
    }
    
    public class CreditAccount(string name, string accountNumber, decimal creditLimit) : Account(name, accountNumber)
    {
        public decimal CreditLimit { get; } = creditLimit;
        
        public override void Withdraw(decimal amount)
        {
            if (amount > Balance + CreditLimit)
            {
                throw new InvalidOperationException("超过信用额度");
            }

            Balance -= amount;
        }
    }
}